﻿using System;
using System.Linq;
using System.Windows.Input;
using Graphing.Services;
using Graphing;

namespace CalculatorProject.ViewModel
{
    public class MainWindowViewModel : ViewModelBase
    {
        #region Fields

        RelayCommand _closeCommand;
        public event EventHandler RequestClose;
        private ThreadingDepositoryService _openWindowThreading = GenericSingleton<ThreadingDepositoryService>.GetInstance();

        #endregion // Fields.

        #region Constructor

        public MainWindowViewModel()
        {
    //        var viewModel = new InputButtonsViewModel();
        }

        #endregion // Constructor.

        #region Close Command

        public ICommand CloseCommand
        {
            get
            {
                if (_closeCommand == null)
                    _closeCommand = new RelayCommand(param => this.OnRequestClose());

                return _closeCommand;
            }
        }

        private void OnRequestClose()
        {
            EventHandler handler = this.RequestClose;

            if (handler != null)
                handler(this, EventArgs.Empty);

            // Close the Graph View, if it is opened.
            _openWindowThreading.CloseViewThread("GraphView");
        }
        #endregion // Close Command.
    }
}
